/*  
Creates table with estimates between "photo uploads" and "perceived beauty"


Requires the clean dataset:
${project}/clean_data/survey_level_data.dta

Arianna Salazar Miranda
*/


clear all
set matsize 5000
global project "/Users/arianna/Dropbox (MIT)/emporis_project/paper/submission_PLOS/data_repository"

**************************************************************************************************
*open survey database
**************************************************************************************************
use "${project}/Data/survey_level_data.dta", clear

**************************************************************************************************
*cleaning
**************************************************************************************************


drop if officialname=="Mark Twain Building"
drop if officialname=="Empire State Building"
drop if officialname=="Byrd's Lofts"

egen s_number = group(session_id)
bysort session_id: gen tag_unique=(_n==_N)


**************************************************************************************************
*define variable labels*
**************************************************************************************************

gen poster = .
replace poster = 1 if anon==1
replace poster =0 if anon==2

label define gender_lab 1 "male" 2 "female", add
label values gender gender_lab

label define edu_lab 1 "high school" 2 "college" 3 "other", add
label values edu edu_lab

label define race_lab 1 "white" 2 "black" 3 "asian" 4 "hispanic" 5 "other", add
label values race race_lab

label define met_lab 1 "metro" 2 "non-metro", add
label values  met met_lab

label define age_lab 1 "more50" 2 "40-50" 3 "30-40" 4 "20-30" 5 "less20", add
label values  age age_lab


global covariates edu met race age gender

foreach var in $covariates {
replace `var' = . if `var' ==0
}


**************************************************************************************************
*Likelihood of Posting*
**************************************************************************************************

quietly: logit poster i.($covariates ) if tag==1
predict logit_prob, pr
margins, dydx(i.$covariates ) atmeans post

**************************************************************************************************
*generate probability quartiles*
**************************************************************************************************

sum logit_prob if tag==1, d
gen quartile_1 = (logit_prob <= r(p25)) if logit_prob !=.
gen quartile_2 = (logit_prob <= r(p50) & logit_prob > r(p25)) if logit_prob !=.
gen quartile_3 = (logit_prob <= r(p75) & logit_prob > r(p50)) if logit_prob !=.
gen quartile_4 = (logit_prob > r(p75)) if logit_prob !=.


**************************************************************************************************
*TABLE 4*
**************************************************************************************************

gen r0_50_count_2014 = (r50_count_picData_2014)/10
gen r0_50_count_flickr = (r50_count_picData_flickr)/10

******************************
* 1) posters and non-posters using panoramio 2014*
******************************
gen no_poster = 1-poster
gen picvar = r0_50_count_2014
areg score c.picvar#c.(no_poster poster)  i.s_number i.photo_count, a(session_id) cluster(buildingnumberebn)


******************************
* 2) predicted posters vs non-posters (4 groups together) panoramio 2014*
******************************
reg score c.picvar#c.(quartile_1 quartile_2 quartile_3 quartile_4) i.s_number i.photo_count,  cluster(buildingnumberebn)


******************************
* 3) posters and non-posters using Flickr*
******************************
replace picvar=r0_50_count_flickr
areg score c.picvar#c.(no_poster poster)  i.s_number i.photo_count, a(session_id) cluster(buildingnumberebn)


******************************
* 4) predicted posters vs non-posters (4 groups together) Flickr*
*****************************
reg score c.picvar#c.(quartile_1 quartile_2 quartile_3 quartile_4) i.s_number i.photo_count,  cluster(buildingnumberebn)

************************************************


 
